
package login;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
/**
 * This class connects to the database and unlocks a user or users.
 * @author Eric
 */
public class AdminDAO {
    static Connection currentCon = null;
    static ResultSet rs = null;
    static int rsNum = 0; 
    /**
    * This is the purpose of the class. It connects to the database and unlocks 
    * a user or users.
    * @param unames of usernames to be unlocked
    */

    public static void unlock(String[] unames) {
        if(unames == null)
            return;
        
        Statement stmt = null;

        String updateQuery = "update users set isLocked='0', consecutiveFails='0' "
                + "where uname in (";
        
        for(String usr : unames)
        {
            updateQuery += "'" + usr + "'" + ",";
        }
        
        updateQuery = updateQuery.substring(0, updateQuery.length()-1) + ")";
        
        try {
            currentCon = ConnectionManager.getConnection();
            stmt = currentCon.createStatement();
            rsNum = stmt.executeUpdate(updateQuery);
        } catch (Exception ex) {
            System.out.println("connection bad-probably database url" + ex);
        }
    }
}